<template>
  <div>
    <el-form
      :model="form"
      :rules="rules"
      ref="form"
      label-width="80px"
      v-loading="loading"
    >
      <el-form-item label="群组名称" prop="name">
        <el-input v-model="form.groupName"></el-input>
      </el-form-item>

      <el-form-item label="头像" prop="portrait">
        <el-input
          v-model="form.portrait"
          placeholder="请输入头像url"
        ></el-input>
      </el-form-item>

      <el-form-item label="群主" prop="name">
        <el-input
          :value="owner.displayName"
          @click.native="showUsers"
        ></el-input>
      </el-form-item>
    </el-form>
    <user-list ref="users" @set-owner="setOwner" />
  </div>
</template>

<script>
import userList from "./user/index.vue";

export default {
  components: { userList },
  data() {
    return {
      form: {},
      rules: {
        // id: [{ required: true, message: "请输入", trigger: "blur" }],
        // url: [{ required: true, message: "请输入", trigger: "blur" }],
      },
      loading: false,
      owner: {},
    };
  },
  created() {},
  methods: {
    showUsers() {
      this.$refs.users.open();
    },
    setOwner(owner) {
      if (owner) {
        this.owner = owner;
      }
    },
    init(row) {
      this.form = row;
      this.$refs.form.clearValidate();
    },
    validate(cb) {
      this.$refs.form.validate((valid) => {
        if (!valid) {
          return;
        }
        cb({
          ...this.form,
          groupExtra: "",
          owner: this.owner.uid,
          ownerName: this.owner.displayName,
          type: "2",
        });
      });
    },
  },
};
</script>

<style>
</style>